mod r#trait;
mod lifetime;

fn main() {
    // println!("Hello, world!");


    let list = [11, 22, 3, 4, 66, 77, 111, 4];
    let largest = find_largest(&list);

    println!("largest is  {}", largest);
}


fn find_largest(list: &[i32]) -> i32 {
    let mut largest = list[0];

    for ele in list {
        if *ele > largest {
            largest = *ele;
        }
    }

    largest
}

//   函数上的泛型


// fn find_largest_t<T>(list: &[T]) -> T {
//     let mut largest = list[0];
// 
//     for ele in list {
//         if *ele > largest {
//             largest = *ele;
//         }
//     }
// 
//     largest
// }

//结构体上的泛型

//一个泛型
#[derive(Debug)]
struct Point<T> {
    x: T,
    y: T,
}

struct Point2<T, U> {
    x: T,
    y: U,
}


// 枚举中的泛型
enum Option<T> {
    Some(T),
    None,
}

enum Result<T, E> {
    Ok(T),
    Err(E),
}


//  泛型结构体的函数


// impl<T> Point<T> {
//     fn new(x: T, y: T) -> Point <T> {
//         Point {
//             x,
//             y,
//         }
//     }
// }


//  不带泛型的
impl Point<i32> {
    fn new(x: i32, y: i32) -> Point <i32> {
        Point {
            x,
            y,
        }
    }
}



#[test]
fn test_point(){



    // let p1 = Point::new("22","33");
    // 
    // println!("p1:{:?}", p1);


    let p1 = Point::new(22,55);

    println!("p1:{:?}", p1);

}